package com.jctrip.hotel.source.xxl.hmein.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.hmein.HmeinTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

/**
 * @Author: zxy
 * @CreateTime: 2023-10-24 21:28
 * @Description:
 */
@Slf4j
public class SyncHmeinPicTaskThread implements Runnable {

    private final String appId;

    public SyncHmeinPicTaskThread(String appId) {
        this.appId = appId;
    }

    @Override
    public void run() {
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
        HmeinTaskService hmeinTaskService = BeanContext.getApplicationContext().getBean(HmeinTaskService.class);
        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_HMEIN_PIC_LIST) > 0) {
            try {
                String hotelId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_HMEIN_PIC_LIST);
                if (StringUtils.isBlank(hotelId)) {
                    continue;
                }
                hmeinTaskService.syncHmeinPic(appId, hotelId);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}